#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int n,m,L,V;
int d[N],a[N];
double v[N];
int p[N],ans=0;
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int T;scanf("%d",&T);
	while(T--){
		ans=0;
		scanf("%d%d%d%d",&n,&m,&L,&V);
		for(int i=1;i<=n;i++)
			scanf("%d%lf%d",&d[i],&v[i],&a[i]);
		for(int i=1;i<=m;i++)
			scanf("%d",&p[i]);
		int P=p[m];
		for(int i=1;i<=n;i++){
			if(a[i])
				v[i]=sqrt(1.0*(v[i]*v[i]+2*a[i]*(P-d[i])));
			if(d[i]<=P&&v[i]>1.0*V)
				ans++;
		}
		if(ans==0)
			printf("%d %d\n",ans,m);
		else
			printf("%d %d\n",ans,m-1);
	}
	
	return 0;
}

